package com.woniuxy.credit_loans.collection_zhang.quartz;

import com.woniuxy.credit_loans.collection_zhang.service.BorWarningService;
import com.woniuxy.credit_loans.collection_zhang.service.BorrowService;
import com.woniuxy.credit_loans.entity.Borrow;
import com.woniuxy.credit_loans.entity.Borwarning;
import com.woniuxy.credit_loans.entity.User;
import com.woniuxy.credit_loans.staff_ma.service.UserService;
import com.woniuxy.credit_loans.util.Email;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.math.BigDecimal;
import java.util.List;

public class DongAoJob extends QuartzJobBean {

    @Autowired
    private BorWarningService borWarningService;

    @Autowired
    private BorrowService borrowService;

    @Autowired
    private UserService userService;

    @Autowired
    private  Email email;

    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
         List<Borrow> list = borrowService.selectAll("");
        for (Borrow borrow:list) {
            Integer borrowId = borrow.getBorrowId();
            String  name=borrow.getUserName();
            System.out.println(name);
            //发送邮件预警
            User user = userService.selectByName(name);
            String userAdd = user.getUserAdd();
            String title="还款预警提示";
            String contextee="尊敬的用户，系统提示您，马上就到您的还款日了，请及时缴纳还款，避免为您早餐不必要的麻烦";
            email.sendMessage(userAdd,title,contextee);


            //后端管理预警
            Borwarning borwarning=new Borwarning();
            borwarning.setBorrowId(borrowId);
            borwarning.setBorwarningGrade("蓝色预警");
            borwarning.setBorwarningDays("7");
            borWarningService.insertSelective(borwarning);
        }
        System.out.println("获得的成功越大，就越令人高兴。野心是使人勤奋的原因，节制使人枯萎。");
    }
}
